#include #include using namespace std; struct FileHeader { char headerField[3]; unsigned int fileSize; unsigned int reserved; unsigned int bmpOffset; }; struct ImageHeader { unsigned int headerSize; //0Eh 4 the size of this header (40 bytes) //12h 4 the bitmap width in pixels (signed integer). //16h 4 the bitmap height in pixels (signed integer). unsigned short colorPlanes; //1Ah 2 the number of color planes being used. Must be set to 1. unsigned short bitsPerPixel;//1Ch 2 the number of bits per pixel, which is the color depth of the image. Typical values are 1, 4, 8, 16, 24 and 32. //1Eh 4 the compression method being used. See the next table for a list of possible values. //22h 4 the image size. This is the size of the raw bitmap data (see below), and should not be confused with the file size. //26h 4 the horizontal resolution of the image. (pixel per meter, signed integer) //2Ah 4 the vertical resolution of the image. (pixel per meter, signed integer) //2Eh 4 the number of colors in the color palette, or 0 to default to 2n. //32h 4 the number of important colors used, or 0 when every color is important; generally ignored. }; struct Image { FileHeader fileHeader; ImageHeader imageHeader; //list of pixels Image(string fileName) { ifstream fin(fileName, ios_base::binary); fin.read(fileHeader.headerField,2); fin.read((char*)(&fileHeader.fileSize),4); fin.read((char*)(&fileHeader.reserved),4); fin.read((char*)(&fileHeader.bmpOffset),4); fin.close(); } void displayHeaders() { cout << fileHeader.headerField << endl; cout << fileHeader.fileSize << endl; cout << fileHeader.reserved << endl; cout << fileHeader.bmpOffset << endl; } }; //encapsulation //information hiding void main() { Image image("image.bmp"); image.displayHeaders(); }